package com.ub.party.internal.service.impl;

import com.ub.party.common.vo.resp.RespVo;
import com.ub.party.internal.dao.BackendUserInfoMapper;
import com.ub.party.internal.service.ShreecService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by Mara on 2015/9/27.
 */
@Service
public class ShreecService2Impl implements ShreecService {

  private static final Logger logger = Logger.getLogger(ShreecService2Impl.class);
  @Autowired
  private com.ub.party.internal.dao.MemberInfoMapper memberInfoMapper;

  @Autowired
  private BackendUserInfoMapper backendUserInfoMapper;

  @Override
  @Transactional(rollbackFor = Exception.class)
  public RespVo saveMember(com.ub.party.internal.model.MemberInfo memberInfo) {
    com.ub.party.internal.model.MemberInfo tempInfo = memberInfoMapper.selectByCellphone(memberInfo.getCellphone());
    tempInfo.setCreateDate(new Date());
    tempInfo.setUpdateDate(new Date());
    memberInfoMapper.insert(tempInfo);
    return RespVo.ok();
  }

  @Override
  public RespVo tryLogin(String username, String password) {
    RespVo respVo = new RespVo();
    com.ub.party.internal.model.BackendUserInfo backendUserInfo = backendUserInfoMapper.selectByUserName(username);

    return respVo;
  }

  @Override
  public List<com.ub.party.internal.model.MemberInfo> getAllMembers() {
    return memberInfoMapper.selectAll();
  }
}
